// packagMy/pages/partnerUsers/partnerUsers.js
var configUrl = require('../../../config/config')  //引入配置接口文件
const app=getApp();
const comUrl=app.globalData.comUrl
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    index: 0,
    isShowNotPage:false,
    page:1,
    row:15,
    userPageList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    })
    wx.setNavigationBarTitle({
      title: '我的线索/客户',
    })
    let parms={}
    this.getListdata(parms)
  },
  onChange(event) {
    var index=event.detail.index
    this.setData({
      index:index,
      userPageList:[],
      page:1,
      isShowNotPage:false
    })
    if(index==0){
      var parms={}
      this.getListdata(parms)
    }else if(index==1){
      var parms={
        isPartner:"Y"
      }
      this.getListdata(parms)
    }else if(index==2){
      var parms={
        isMember:"Y"
      }
      this.getListdata(parms)
    }else if(index==3){
      var parms={
        isMember:"N"
      }
      this.getListdata(parms)
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  
  getListdata(parms) {
    var that=this
    var userId=wx.getStorageSync('loginMsg').userId
    let parmsData = parms
    parmsData.page = that.data.page
    parmsData.rows = that.data.row
    parmsData.pageFlag = false
    app.reqFun.requestForm('POST',configUrl.partnerPage+userId,parmsData,(res)=>{
      if(res.data.success==1){
        var userPageList = res.data.data.records
        if(userPageList.length < that.data.row){
          that.setData({
            isShowNotPage:true
          })
        }
        that.setData({
          userPageList: that.data.userPageList.concat(userPageList)
        })
      }else{
        wx.showToast({
          title: '获取数据失败',
          icon:'none'
        })
      }
    })
  },
  userFootprint(e) {
    let id = e.currentTarget.dataset.key.id
    wx.navigateTo({
      url: '/packagMy/pages/userFootprint/userFootprint?id='+ id,
    })
    let userPageList = this.data.userPageList
    for (var i in userPageList) {
      if (userPageList[i].id == id) {
        userPageList[i].unReadFootprintCount = null
      }
    }
    this.setData({
      userPageList:userPageList
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var index=this.data.index
    this.setData({
      userPageList:[],
      page:1,
      isShowNotPage:false
    })
    if(index==0){
      var parms={}
      this.getListdata(parms)
    }else if(index==1){
      var parms={
        isPartner:"Y"
      }
      this.getListdata(parms)
    }else if(index==2){
      var parms={
        isMember:"Y"
      }
      this.getListdata(parms)
    }else if(index==3){
      var parms={
        isMember:"N"
      }
      this.getListdata(parms)
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})